// let appId = "wx855361a721050c6b"//测试
let appId = "wxa1439f77c6d06a15" //正式

import {
  network
} from "./api"

// 提现打款 实名认证or手动签

const withdrawal = (type = 1, bank_id = '') => {
  return new Promise((reslove, reject) => {
    getApp().globalData.posts(
      '/index.php/api/ouyoung/Third/maker_auth_url/uid/' + wx.getStorageSync('userInfo').id + '?type=' + type + '&bank_id=' + bank_id,
    ).then(res => {
      let jump = res.data.data.jump;
      let url = res.data.data.url;
      if (jump == 1) {
        wx.navigateToMiniProgram({
          appId,
          path: 'pages/result-loading/result-loading?verifyUrl=' + encodeURIComponent(url)
        })
      } else if (jump == 2) {
        wx.navigateTo({
          url: '/pages/webview/rich?url=' + encodeURIComponent(network + '?' + url),
        })
      } else if (jump == 3) {
        getApp().showModal(res.data.msg)
      } else {
        getApp().globalData.posts(
          '/index.php/api/ouyoung/Third/maker_sign_url/uid/' + wx.getStorageSync('userInfo').id + '?type=' + type + '&bank_id=' + bank_id,
        ).then(r => {
          let jumps = r.data.data.jump;
          let urls = r.data.data.url;
          if (jumps == 1) {
            wx.navigateToMiniProgram({
              appId,
              path: 'pages/h5sign/h5sign',
              extraData: {
                verifyUrl: urls
              }
            })
          } else if (jumps == 2) {
            wx.navigateTo({
              url: '/pages/webview/rich?url=' + encodeURIComponent(network + '?' + urls),
            })
          } else if (jumps == 3) {
            getApp().showModal(r.data.msg)
          } else {
            if (r.data.code == 1) {
              reslove(r.data.msg)
            }
          }
        })
      }
    })
  })
}

const show_withdrawal = (type = 1, bank_id = '') => {
  return new Promise((reslove, reject) => {
    getApp().globalData.posts(
      '/index.php/api/ouyoung/Third/maker_auth_url/uid/' + wx.getStorageSync('userInfo').id + '?type=' + type + '&bank_id=' + bank_id,
    ).then(res => {
      let jump = res.data.data.jump;
      let url = res.data.data.url;
      if (jump == 1) {
        reject({
          step: 1,
          obj: {
            appId,
            path: 'pages/result-loading/result-loading?verifyUrl=' + encodeURIComponent(url)
          }
        })
      } else if (jump == 2) {
        wx.navigateTo({
          url: '/pages/webview/web?url=' + encodeURIComponent(network + '?' + url),
        })
      } else if (jump == 3) {
        getApp().showModal(res.data.msg)
      } else {
        getApp().globalData.posts(
          '/index.php/api/ouyoung/Third/maker_sign_url/uid/' + wx.getStorageSync('userInfo').id + '?type=' + type + '&bank_id=' + bank_id,
        ).then(r => {
          let jumps = r.data.data.jump;
          let urls = r.data.data.url;
          if (jumps == 1) {
            reject({
              step: 2,
              obj: {
                appId,
                path: 'pages/h5sign/h5sign',
                extraData: {
                  verifyUrl: urls
                }
              }
            })
          } else if (jumps == 2) {
            wx.navigateTo({
              url: '/pages/webview/web?url=' + encodeURIComponent(network + '?' + urls),
            })
          } else if (jumps == 3) {
            getApp().showModal(r.data.msg)
          } else {
            reslove(r.data.msg)
          }
        })
      }
    })
  })
}

module.exports = {
  withdrawal,
  show_withdrawal
}